package leetcode_solutions.code51_100;

/**
 * @author Synhard
 * @version 1.0
 * @class Code73
 * @description TODO
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-11-09 9:19
 */
public class Code73 {


    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode l1 = headA;
        ListNode l2 = headB;
        while (true) {
            if (l1 == l2) {
                return l1;
            }
            if (l1 == null) {
                l1 = headB;
                l2 = l2.next;
                continue;
            }
            if (l2 == null) {
                l2 = headA;
                l1 = l1.next;
                continue;
            }
            l1 = l1.next;
            l2 = l2.next;
        }
    }
}
